package com.dongnao.lsn_18_classdemo;


import android.content.Context;
import android.graphics.Color;
import android.util.AttributeSet;
import android.view.ViewGroup;
import android.widget.RelativeLayout;

/**
 * 完成组合
 * 提取，组合，转移
 */
public class MenuPutLayout extends RelativeLayout {


    public MenuPutLayout(MenuContentLayout contentLayout) {
        super(contentLayout.getContext());
        init(contentLayout);
    }

    public MenuPutLayout(Context context) {
        super(context);
    }

    public MenuPutLayout(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public MenuPutLayout(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    //线性布局
    MenuContentLayout contentLayout;
    //背景
    MenuBgView bgView;


    public void init(MenuContentLayout contentLayout){
        //转移LinearLayout的宽高给当前
        setLayoutParams(contentLayout.getLayoutParams());
        this.contentLayout = contentLayout;
        //转移背景色
        bgView = new MenuBgView(getContext());
        bgView.setColor(contentLayout.getBackground());
        contentLayout.setBackgroundColor(Color.TRANSPARENT);

        //进行设置
        addView(bgView);
        addView(contentLayout,new LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
    }


    public void setTouchY(float y,float percent){
        bgView.setTouchY(y,percent);
        contentLayout.setTouchY(y,percent);
    }

}
